package wci.intermediate.symtabimpl;

import java.util.Collection;
import java.util.Collections;
import java.util.TreeMap;

import wci.intermediate.SymTab;
import wci.intermediate.SymTabEntry;
import wci.intermediate.SymTabFactory;

/**
 * <h1>SymTabImpl</h1>
 *
 * <p>符号表实现</p>
 *
 * <p>Copyright (c) 2009 by Ronald Mak</p>
 * <p>For instructional purposes only.  No warranties.</p>
 */
public class SymTabImpl
    extends TreeMap<String, SymTabEntry>
    implements SymTab
{
	private static final long serialVersionUID = -3980285390542271131L;
	private final int nestingLevel; //所在嵌套层次

    public SymTabImpl(int nestingLevel)
    {
        this.nestingLevel = nestingLevel;
    }
    public int getNestingLevel()
    {
        return nestingLevel;
    }
    public SymTabEntry enter(String name)
    {
        SymTabEntry entry = SymTabFactory.createSymTabEntry(name, this);
        put(name, entry);

        return entry;
    }

    public SymTabEntry lookup(String name)
    {
        return get(name);
    }
	@Override
	public Collection<SymTabEntry> sortedEntries() {
		return Collections.unmodifiableCollection(values());
	}

    
}
